import { Base } from '../../../utils/base.js'
const app = getApp()
class Favorite extends Base {
  constructor() {
    super()
  }
  /*向收藏添加项目*/
  addFavoriteData(data, callback) {
    let school_id = wx.getStorageSync('school_id')
    let param = {
      url: app.globalData.api + '/api/v1.0/favorites/add/' + school_id,
      data,
      type: 'POST',
      showLoading: true,
      sCallback: (res) => {
        callback && callback(res.data)
      }
    }
    this.request(param)
  }

  /*查询收藏数据*/
  getFavoriteData(data, callback) {
    let school_id = wx.getStorageSync('school_id')
    let param = {
      url: app.globalData.api + '/api/v1.0/favorites/list/' + school_id,
      data,
      sCallback: (res) => {
        callback && callback(res.data.data)
      }
    }
    this.request(param)
  }

  /*查询一个产品是否收藏*/
  getFavoriteProductData(data, callback) {
    let school_id = wx.getStorageSync('school_id')
    let param = {
      url: app.globalData.api + '/api/v1.0/favorites/product/' + school_id,
      data,
      sCallback: (res) => {
        callback && callback(res.data.data)
      }
    }
    this.request(param)
  }

  /*删除收藏项目*/
  deleteFavoriteData(data, callback) {
    let school_id = wx.getStorageSync('school_id')
    let param = {
      url: app.globalData.api + '/api/v1.0/favorites/delete/' + school_id,
      data,
      type: 'DELETE',
      sCallback: (res) => {
        callback && callback(res.data)
      }
    }
    this.request(param)
  }
}

export { Favorite }
